package com.etc;

import com.etc.controller.AController;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.HashMap;
import java.util.List;
import java.util.Set;


@MapperScan("com.etc.dao")
@SpringBootApplication
public class MySpringBootStart implements CommandLineRunner {

    public static void main(String[] args) {

        SpringApplication.run(MySpringBootStart.class, args);
    }

    // 容器对象
    @Autowired
    ApplicationContext applicationContext;

    @Override
    public void run(String... args) throws Exception {
        // 容器获取 所有的 bean的name
        String[] beannames = applicationContext.getBeanDefinitionNames();
        // 循环所有的beanname
        for (String beanname : beannames) {
            // 容器 中 根据  beanname 获取对象
            Object o = applicationContext.getBean(beanname);
            // 打印 beanname ,和 对象
            System.out.println(beanname + "@@@:@@@" + o);
        }

        System.out.println("----------容器中的对象是单例------------");
        Student student = applicationContext.getBean(Student.class);
        System.out.println(student.getName());
        Student student2 = applicationContext.getBean(Student.class);
        System.out.println(student2.getGoods());
        System.out.println("---------------------------------");
        AController controller = applicationContext.getBean(AController.class);
        List<HashMap> lll = controller.show();

        for (int i = 0; i < lll.size(); i++) {
            HashMap map = lll.get(i);
            Set<String> keys = map.keySet();
            for (String key : keys) {
                Object value = map.get(key);
                System.out.print(key + "@@@" + value + "\t");
            }
            System.out.println();
        }

//  LAMBDA
//        lll.forEach(item -> {
//            item.forEach((k,v) -> {
//                System.out.print(k + "@@@" + v + "\t");
//            });
//            System.out.println();
//        });

    }
}
